package com.foo.cms.service.impl;

import com.foo.cms.service.ArticleRelatedService;
import com.foo.cms.service.BaseService;
import com.foo.cms.vo.Article;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: LZS
 * Date: 12-6-25
 * Time: 下午10:51
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ArticleRelatedServiceImpl extends BaseService implements ArticleRelatedService {

    private static final Logger logger = LoggerFactory.getLogger(ArticleRelatedServiceImpl.class);


    @Override
    public List<Article> list(String id) {
        List<Article> articleList = new ArrayList<Article>();
        String sql = "select a.numarticleid , a.vc2title from dt_article_related ar , dt_article a where ar.numartrelid = a.numarticleid and ar.numarticleid = " + id;

        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new HashMap<String, Object>());
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            Article article = new Article();
            article.setId(String.valueOf(map.get("numarticleid")));
            article.setTitle(String.valueOf(map.get("vc2title")));
            articleList.add(article);
            logger.info(article.toString());
        }
        return articleList;
    }
}
